package department;

import java.rmi.RemoteException;
import java.util.Collection;
import java.util.Vector;

import javax.ejb.CreateException;
import javax.ejb.EJBException;
import javax.ejb.EntityBean;
import javax.ejb.EntityContext;
import javax.ejb.RemoveException;
import javax.ejb.SessionContext;

import academicSup.AcademicSup;
import degree.Degree;
import descriptor.DepartmentDescriptor;

/**
 * DepartmentBean
 * 
 * 
 * The DepartmentBean class implements all the methods that a remote client expect to find
 * when it calls the interface (Department).
 * 
 * Note :  -We use @SuppressWarnings("unchecked") to avoid the useless warnings
 */
@SuppressWarnings("unchecked")
public abstract class DepartmentBean implements EntityBean 
{	
	// simple attributes
	public abstract int getId();
	public abstract void setId(int id);
	
	public abstract String getName();
	public abstract void setName(String name);
	
	public abstract Collection<AcademicSup> getAcademicSups();
	public abstract void setAcademicSups(Collection<AcademicSup> academicSups);
	
	public abstract Collection<Degree> getDegrees();
	public abstract void setDegrees(Collection<Degree> degrees);
	
	public DepartmentDescriptor getDescriptor(){
		int[] academicSupIds = new int[getAcademicSups().size()];
		int i=0;
		for (AcademicSup as: getAcademicSups()){
			academicSupIds[i] = as.getId();
			i++;
		}
		int[] degreeIds = new int[getDegrees().size()];
		i=0;
		for (Degree d: getDegrees()){
			degreeIds[i] = d.getId();
			i++;
		}
		return new DepartmentDescriptor(getId(),getName(),academicSupIds,degreeIds);
	}
	
	public String ejbCreate(String name) throws CreateException
	{  	
		setName(name);
		setAcademicSups(new Vector<AcademicSup>());
		setDegrees(new Vector<Degree>());
		
		return null;
	}
	
	public void ejbPostCreate(String name) throws CreateException{}
	public void ejbRemove() throws EJBException, RemoteException, RemoveException{}
	public void ejbActivate() throws EJBException, RemoteException {}
	public void ejbPassivate() throws EJBException, RemoteException {}
	public void setSessionContext(SessionContext arg0) throws EJBException, RemoteException {}
	public void ejbLoad() throws EJBException, RemoteException {}
	public void ejbStore() throws EJBException, RemoteException {}
	public void setEntityContext(EntityContext arg0) throws EJBException, RemoteException {}
	public void unsetEntityContext() throws EJBException, RemoteException {}
}